<template>
  <div class="home-container">
    <el-container>
      <el-aside width="200px">
        <el-menu
          :router="true"
          default-active="/home/resources"
          class="el-menu-vertical"
        >
          <el-menu-item index="/home/resources">
            <el-icon><Document /></el-icon>
            <span>资源列表</span>
          </el-menu-item>
          <el-menu-item index="/home/my-resources">
            <el-icon><Files /></el-icon>
            <span>我的资源</span>
          </el-menu-item>
          <el-menu-item index="/home/borrowed">
            <el-icon><Collection /></el-icon>
            <span>借用记录</span>
          </el-menu-item>
        </el-menu>
      </el-aside>
      <el-container>
        <el-header>
          <div class="header-content">
            <h2>社区资源共享平台</h2>
            <div class="user-info">
              <el-dropdown>
                <span class="el-dropdown-link">
                  {{ userInfo.username }}
                  <el-icon class="el-icon--right"><arrow-down /></el-icon>
                </span>
                <template #dropdown>
                  <el-dropdown-menu>
                    <el-dropdown-item @click="handleLogout">退出登录</el-dropdown-item>
                  </el-dropdown-menu>
                </template>
              </el-dropdown>
            </div>
          </div>
        </el-header>
        <el-main>
          <router-view></router-view>
        </el-main>
      </el-container>
    </el-container>
  </div>
</template>

<script setup lang="ts">
import { Document, Files, Collection, ArrowDown, User } from '@element-plus/icons-vue'
import { useUserStore } from '../stores/user'
import { storeToRefs } from 'pinia'
import { useRouter } from 'vue-router'

const userStore = useUserStore()
const { userInfo } = storeToRefs(userStore)
const router = useRouter()

const handleLogout = () => {
  userStore.logout()
}
</script>

<style scoped>
.home-container {
  height: 100vh;
}

.el-container {
  height: 100%;
}

.el-aside {
  background-color: #fff;
  border-right: 1px solid #e6e6e6;
}

.el-header {
  background-color: #fff;
  border-bottom: 1px solid #e6e6e6;
  padding: 0 20px;
}

.header-content {
  display: flex;
  justify-content: space-between;
  align-items: center;
  height: 100%;
}

.el-menu-vertical {
  border-right: none;
}

.user-info {
  display: flex;
  align-items: center;
}

.el-dropdown-link {
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  color: #606266;
}

.user-avatar {
  background-color: var(--el-color-primary);
  color: #fff;
}

.el-main {
  background-color: #f5f7fa;
  padding: 20px;
}
</style> 